<?php
namespace Shopmanage\Controller;
use Think\Controller;
class ServiceController extends ExtendController {
	public function items(){

		$Q = I("get.q");
		$pg = I("get.pg");
		$items = I("get.numiids");
		if($items){
			Vendor('taobaosdk.top.request.ItemsSellerListGetRequest');
			$req = new \ItemsSellerListGetRequest;
			$req->setFields("num_iid,title,price,pic_url");
			$req->setNumIids($items);
			$resp = $this->c->execute($req, session("access_token"));
			$resp->total_results=count(explode(",",$items));
		}else{
			Vendor('taobaosdk.top.request.ItemsOnsaleGetRequest');
			$req = new \ItemsOnsaleGetRequest;
			// $req = new \ItemsInventoryGetRequest;
			$req->setFields("num_iid,title,price,pic_url");
			$req->setQ($Q);
			$req->setPageNo($pg);
			$req->setPageSize(20);
			$this->c->format="json";
			$resp = $this->c->execute($req, session("access_token"));
			// $resp = $this->c->execute($req, "61023226da00f361e9545ba3f63b1a1319e80fb22d92ba42091447935");
			// $resp = $this->c->execute($req, "6100b078b20d92f1c99b0d6e703c648054ec9a9888c923944173724");
		}
		if(C("TAE")){
			foreach($resp->items->item as $k=>$item){
				$resp->items->item[$k]->title=urlencode_utf8($item->title);
				// $resp->items->item[$k]->title=urlencode(iconv("GBK","UTF-8//IGNORE",$item->title));
			}
		}else{
			foreach($resp->items->item as $k=>$item){
				$resp->items->item[$k]->title=urlencode($item->title);
			}
		}
		$data["msg"] = $resp->msg.$resp->sub_msg;
		$data["items"]["item"]=$resp->items->item;
		$data["total_results"]=(string)$resp->total_results;
		$data["request_id"]=(string)$resp->request_id;
		$data["q"] = $Q;
		$this->ajaxReturn($data);
	}
	public function test(){
		 
		Vendor('taobaosdk.top.request.TradeGetRequest');
		$req = new \TradeGetRequest;
		$req->setFields("tid,type,status,payment,orders,pay_time,buyer_nick");
		$req->setTid("2537870424315505");
		$resp = $this->c->execute($req, "6100b078b20d92f1c99b0d6e703c648054ec9a9888c923944173724");
		print_r($resp);
	}
}